<?php
/* @var $this GiangvienController */
/* @var $model Giangvien */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'giangvien-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Điền đầy đủ vào vị trí có dấu <span class="required">*</span>.</p>

	<?php echo $form->errorSummary($model); ?>
	<table>
	<div class="row">
		  <tr>
			<td style="width:30%;"><?php echo $form->labelEx($model,'magv'); ?></td>
			<td><?php echo $form->textField($model,'magv',array('maxlength'=>128)); ?></td>
			<td><?php echo $form->error($model,'magv'); ?></td>
		  </tr>
	</div>

	<div class="row">
		  <tr>
			<td><?php echo $form->labelEx($model,'tengv'); ?></td>
			<td><?php echo $form->textField($model,'tengv',array('maxlength'=>128)); ?></td>
			<td><?php echo $form->error($model,'tengv'); ?></td>
		  </tr>
	</div>

	<?php 
		$connection=Yii::app()->db;   // assuming you have configured a "db" connection
		$command=$connection->createCommand()
		->select('mangach,tenngach')
		->from('ngach')
		//->where(array('and','username="'.$this->username.'"','level>0'))
		->query();
		$ngach= array();
		foreach($command as $row)
		{
			//array_push($ngach,$row);
			$ngach[$row['mangach']]=$row['tenngach'];
		}
	?>
	
	<div class="row">
		  <tr>
			<td><?php echo $form->labelEx($model,'mangach'); ?></td>
			<td><?php echo $form->dropDownList($model,'mangach',$ngach,array('empty'=>'')); ?></td>
			<td><?php echo $form->error($model,'mangach'); ?></td>
		  </tr>
	</div>
	
	<div class="row">
		  <tr>
			<td><?php echo $form->labelEx($model,'chucdanhhocvi'); ?></td>
			<td><?php echo $form->dropDownList($model,'chucdanhhocvi',array('Cử nhân','Thạc sĩ','Tiến sĩ','Phó Giáo sư','Giáo sư'),array('empty'=>'')); ?></td>
			<td><?php echo $form->error($model,'chucdanhhocvi'); ?></td>
		  </tr>
	</div>

	<div class="row">
		  <tr>
			<td><?php echo $form->label($model,'isMale'); ?></td>
			<td><?php echo $form->radioButtonList($model,'isMale',array('1'=>'Nam','0'=>'Nữ'),array('separator'=>'', 'labelOptions'=>array('style'=>'display:inline;margin:0 2em 0 0;')));?></td>
			<td><?php echo $form->error($model,'isMale'); ?></td>
		  </tr>
	</div>

	<?php 
		$now=getdate();
		$year=array();
		for($i=$now['year']-55;$i<$now['year']-21;$i++)
			$year[$i]=$i;
	?>
	
	<div class="row">
		  <tr>
			<td><?php echo $form->labelEx($model,'namsinh'); ?></td>
			<td><?php echo $form->dropDownList($model,'namsinh',$year,array('empty'=>'')); ?></td>
			<td><?php echo $form->error($model,'namsinh'); ?></td>
		  </tr>
	</div>

	<div class="row">
		  <tr>
			<td><?php echo $form->labelEx($model,'sodtgv'); ?></td>
			<td><?php $this->widget('CMaskedTextField', array(
					'mask' => '99999999999',
					//'placeholder' => 'yyyy/mm/dd',
					//'completed' => 'function(){alert();}',
					'model' => $model,
					'name' => 'sodtgv',
					'attribute'=> 'sodtgv',
				));?>
			</td>
			<td><?php echo $form->error($model,'sodtgv'); ?></td>
		  </tr>
	</div>

	<?php 
		//$connection=Yii::app()->db;   // assuming you have configured a "db" connection
		$commandDV=$connection->createCommand()
		->select('madonvi,tendonvi')
		->from('donvicongtac')
		->query();
		$donvi= array();
		foreach($commandDV as $rowDV)
		{
			//array_push($ngach,$row);
			$donvi[$rowDV['madonvi']]=$rowDV['tendonvi'];
		}
	?>
	
	<div class="row">
		  <tr>
			<td><?php echo $form->labelEx($model,'madonvi'); ?></td>
			<td><?php echo $form->dropDownList($model,'madonvi',$donvi,array('empty'=>'')); ?></td>
			<td><?php echo $form->error($model,'madonvi'); ?></td>
		  </tr>
	</div>

	<div class="row">
		  <tr>
			<td><?php echo $form->labelEx($model,'chuyennganh'); ?></td>
			<td><?php echo $form->textField($model,'chuyennganh'); ?></td>
			<td><?php echo $form->error($model,'chuyennganh'); ?></td>
		  </tr>
	</div>

	<div class="row">
		  <tr>
			<td><?php echo $form->labelEx($model,'diachi'); ?></td>
			<td><?php echo $form->textField($model,'diachi'); ?></td>
			<td><?php echo $form->error($model,'diachi'); ?></td>
		  </tr>
	</div>

	<div class="row">
		  <tr>
			<td><?php echo $form->labelEx($model,'cmnd'); ?></td>
			<td><?php $this->widget('CMaskedTextField', array(
					'mask' => '9999999999',
					'model' => $model,
					'name' => 'cmnd',
					'attribute'=> 'cmnd',
				));?>
			</td>
			<td><?php echo $form->error($model,'cmnd'); ?></td>
		  </tr>
	</div>

	<div class="row">
		  <tr>
			<td><?php echo $form->labelEx($model,'ngaycap'); ?> (yyyy-mm-dd)</td>
			<td><?php $this->widget('CMaskedTextField', array(
					'mask' => '9999-99-99',
					//'placeholder' => 'yyyy/mm/dd',
					//'completed' => 'function(){alert();}',
					'model' => $model,
					'name' => 'ngaycap',
					'attribute'=> 'ngaycap',
				));?> 
			</td>
			<td><?php echo $form->error($model,'ngaycap'); ?></td>
		  </tr>
	</div>

	<div class="row">
		  <tr>
			<td><?php echo $form->labelEx($model,'noicap'); ?></td>
			<td><?php echo $form->textField($model,'noicap'); ?></td>
			<td><?php echo $form->error($model,'noicap'); ?></td>
		  </tr>
	</div>

	<div class="row">
		  <tr>
			<td><?php echo $form->labelEx($model,'masothue'); ?></td>
			<td><?php echo $form->textField($model,'masothue',array('size'=>60,'maxlength'=>128)); ?></td>
			<td><?php echo $form->error($model,'masothue'); ?></td>
		  </tr>
	</div>

	<div class="row">
		  <tr>
			<td><?php echo $form->labelEx($model,'namvaotruong'); ?></td>
			<td><?php echo $form->dropDownList($model,'namvaotruong',$year,array('empty'=>'')); ?></td>
			<td><?php echo $form->error($model,'namvaotruong'); ?></td>
		  </tr>
	</div>

	<div class="row">
		  <tr>
			<td><?php echo $form->labelEx($model,'loaihinh'); ?></td>
			<td><?php echo $form->dropDownList($model,'loaihinh',array('gvch'=>'Giảng viên cơ hữu','gvmg'=>'Giảng viên mời giảng','gvtgtt'=>'Giảng viên thỉnh giảng trong trường','gvtgnt'=>'Giảng viên thỉnh giảng ngoài trường'),array('empty'=>'')); ?></td>
			<td><?php echo $form->error($model,'loaihinh'); ?></td>
		  </tr>
	</div>

	<div class="row">
		  <tr>
			<td><?php echo $form->label($model,'nghiencuusinh'); ?></td>
			<td><?php echo $form->checkBox($model,'nghiencuusinh'); ?></td>
			<td><?php echo $form->error($model,'nghiencuusinh'); ?></td>
		  </tr>
	</div>

	<div class="row">
		  <tr>
			<td><?php echo $form->label($model,'giangvientapsu'); ?></td>
			<td><?php echo $form->checkBox($model,'giangvientapsu'); ?></td>
			<td><?php echo $form->error($model,'giangvientapsu'); ?></td>
		  </tr>
	</div>

	
	<div class="row">
		  <tr>
			<td><?php echo $form->labelEx($model,'khoagiangday'); ?></td>
			<td><?php 
					$commandDV=$connection->createCommand()
					->select('madonvi,tendonvi')
					->from('donvicongtac')
					->query();
					$khoa= array();
					foreach($commandDV as $rowDV)
					{
						//array_push($ngach,$row);
						if(substr( $rowDV['madonvi'],0,1)=='K')
						{
						$khoa[$rowDV['madonvi']]=$rowDV['tendonvi'];}
					}
					
						$this->widget('ext.widgets.select2.XSelect2', array(
							'model'=>$model,
							'attribute'=>'khoagiangday',
							'data'=>$khoa,
							'options'=>array(
								'maximumSelectionSize'=>10,
							),
							'htmlOptions'=>array(
								'style'=>'width:20.5em',
								'multiple'=>'true'//,
							   // 'class'=>'countries-select'
							),
							'events'=>array(
								'selected'=>"js:function (element) {
									$('[data-khoa='+element.val+']').hide();
								}",
								'removed'=>"js:function (element) {
									$('[data-khoa='+element.val+']').show();
								}"
							),
						)); 
				?></td>
			<td><?php echo $form->error($model,'khoagiangday'); ?></td>
		  </tr>
	</div>

	<div class="row">
		  <tr>
			<td><?php echo $form->labelEx($model,'ghichu'); ?></td>
			<td><?php echo $form->textField($model,'ghichu',array('rows'=>6, 'cols'=>50)); ?></td>
			<td><?php echo $form->error($model,'ghichu'); ?></td>
		  </tr>
	</div>
	</table>
	
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Tạo mới' : 'Lưu'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->